<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>添加账户</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/admin.css"/>
    <link rel="stylesheet" type="text/css" href="../css/lift.css">
    <style>
      .layui-form{
      width: 350px;
      height:300px;
      margin:0 auto;
      }
      .add-name th{
        width:100px;
        height:40px;
        font-size:14px;
        padding: 0;
        vertical-align: middle;
      }
      .add-name input{
        outline:none;
        width:160px;
        height: 28px;
        border:1px solid #E5BA70;
        border-radius:5px;
      }
      .tianjia-checkBox th{
        width:88px;
        height:40px;
        font-size:18px;
        padding-top:20px;

      }
      tr.tianjia-checkBox td input{
        margin-left:10px;
        display: inline-block;
      }
      .layui-table td, .layui-table th{
        padding:3px 12px;
      }
      .layui-form h3,.layui-form .role_name{
        margin-left:30px;
        margin-bottom:10px;
      }
    .layui-form .role_name{
      width:145px;
      height:25px;
       border-radius:5px;
       border:1px solid #888;
       display:inline-block;
    }
      .layui-form .layui-table{
        margin-top:50px;
        margin:0 auto;
      }
     .layui-input-block  span{
      font-size: 14px;
    }
    .layui-input-block th{
       font-size: 14px;
    }
    #btn-c,#btn-s{
      border:0;
      width: 100px;
      height: 28px;
      margin-top:15px;
      border-radius:5px;
      background-color: #D8D8D8;
    }
    #btn-c{
       margin-left:70px;
    }
    #btn-s:hover,#btn-c:hover{
      color:#fff;
     background-color:#EF7632;
    }
    #btn-s{
        margin-left:15px;
    }
    .layui-layer .layui-layer-title{
      background-color: #fff;
    }
    .layui-form-radio{
      padding:0;
      margin:0;
      margin-left:90px;
    }
 .layui-table-add{
  margin-left:30px;
 }
 </style>
</head>
<body>
     <form class="layui-form" action="">

   <h3 style="display:inline-block">物业公司</h3>
     <input type="text" class="role_name" id="company_name" value="" onfocus="this.style.color='#777';
      this.value='';"  onblur="this.style.color='#777';  this.value=this.value"  disabled /> <br>
   <h3 style="display:inline-block">用户名称</h3>
     <input type="text" class="role_name"  id="user_name" value="" onfocus="this.style.color='#777';
      this.value='';"  onblur="this.style.color='#777';  this.value=this.value" disabled/><br>
   <h3 style="display:inline-block">账&emsp;&emsp;号</h3>
     <input type="text"  class="role_name" id="user_tel" value="" onfocus="this.style.color='#777';
      this.value='';"  onblur="this.style.color='#777';  this.value=this.value" /><br>
   <h3>账户角色:&emsp;</h3>
     <table class="layui-table layui-table-add" lay-skin="nob">
            <tbody  class="admin" >
          </tbody>
        </table>
          <input type="button" id="btn-c" value="取消">
          <input type="button" id="btn-s" value="保存">
      </form>
  <script type="text/javascript" src="../layui/layui.js"></script>
  <script>
      layui.use(['jquery','form','upload','layer'], function(){
            var $ = layui.jquery,layer = layui.layer;
            var element = layui.element;
            var params={};
            var form = layui.form();

            var current_page = 1;
 //获取账户角色并渲染，获取角色id并取出
     $.ajax({
          url: '../../role_manage/queryWuyeRoles',
          type: 'get',
          dataType: 'json',
          data:{
                current_page: current_page,
                limit:10
               },
          success:function(response){
                 console.log("success",response);
          if(response.resultCode == 200){
                var str= '';
                console.log(response.page.list.length);
          if(response.page.list.length){
            for(var i=0;i<response.page.list.length;i++){

            var role_Name =localStorage.getItem("roleNameID");
            console.log(role_Name);
          if(role_Name == response.page.list[i].role_name){
            str +=
             '<tr>'+
            '<td class="check"><input data-id="'+ response.page.list[i].role_id +'"  type="radio" name="items" value="'+response.page.list[i].role_name+'" title="'
            +response.page.list[i].role_name+'" lay-skin="line" checked></td>'+
            '</tr>'
             }else if(role_Name !== response.page.list[i].role_name){
              str +=
             '<tr>'+
            '<td class="check"><input data-id="'+ response.page.list[i].role_id +'"  type="radio" name="items" value="'+response.page.list[i].role_name+'" title="'
            +response.page.list[i].role_name+'" lay-skin="line"></td>'+
            '</tr>'
             }
          }
          $(".admin").html(str);

           form.render();
          }

         }
        },
           error:function(response){
              console.log("error",response);
              if(response.resultCode=='001'){
                console.log("param is not found");
                }else if(response.resultCode=='009'){
                  console.log("String is not int type");
                }
            }
        })
//获取表单中数据并保存
      $("#btn-s").off("click").on("click",function(){

        var company_name = $("#company_name").val();
            params.company_name = company_name;

        var user_name = $("#user_name").val();
            params.user_name = user_name;

        var user_tel = $("#user_tel").val();
            params.user_tel = user_tel;

        var superior_id = localStorage.getItem("user_id");
            params.superior_id  = superior_id;

        var role_id= $("input[name='items']:checked").attr("data-id");
            params.role_id  = role_id;

        var user_id = localStorage.getItem("wuyeID");
            params.user_id  =user_id;

       if(company_name &&user_name&&user_tel){
         $.ajax({
           url: '../../wuye_account/updateWuYeUser',
           type: 'POST',
           dataType: 'json',
           data: params,
           success: function(response){
             console.log("updateWuYeUser",response);
               alert("修改成功！")
               window.parent.location.reload();
               var index=parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);
             if(response.resultCode == 200){
                 console.log("updateWuYeUser success");
            }
          },
           error:function(response){
              console.log("fail",response);
               alert("修改失败！")
               window.parent.location.reload();
               var index=parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);

              if(response.resultCode==001){
                console.log("param is not found")
                }else if(response.resultCode==009){
                   console.log("String is not int tpye")
                 }else if(response.resultCode==002){
                   console.log("Phone number is not vaild")
                 }
            }
        })
      }

    })
   $("#btn-c").click(function(){
      window.parent.location.reload();
      var index=parent.layer.getFrameIndex(window.name);
      parent.layer.close(index);
     })
        });
  </script>
</body>
</html>
